$(function () {
    //======================
    //======设置查询条件========
    //======================
    var selectData={"id":$("#ejzhmx_detail_toolbar [name='id']").val(),"jc":$("#ejzhmx_detail_toolbar [name='jc']").val()};
    //内部公司
    $("#ejzhmx_detail_toolbar [name='gsId']").gsjgtree(1);
    //起始时间
    $("#ejzhmx_detail_toolbar [name='dateStart']").datebox();
    $("#ejzhmx_detail_toolbar [name='dateEnd']").datebox();
    $("#ejzhmx_detail_toolbar [name='khId']").qyjgzcombobox({
        selectData:selectData
    });
    //搜索按钮
    $("#ejzhmx_detail_toolbar [name='searchButton']").click(function () {
        if(!$("#ejzhmx_detail_toolbar [name='khId']").val()) {
            $.messager.alert("提示","请选择客户！","info");
            return;
        }
        $(detailGrid).datagrid({
            queryParams: {
                khId: $("#ejzhmx_detail_toolbar [name='khId']").val(),
                dateStart: $("#ejzhmx_detail_toolbar [name='dateStart']").val(),
                endDate: $("#ejzhmx_detail_toolbar [name='dateEnd']").val(),
                nbgsId: $("#ejzhmx_detail_toolbar [name='nbgsId']").val()
            }});
    });


//======================
//========统计列表========
//======================
    var detailGrid = $("#ejzhmx_detail_grid").datagrid({
        url: $.webPath() + '/report/wlz/ejzhyemxList',
        toolbar: "#ejzhmx_detail_toolbar",
        rownumbers: true,
        pagination:true,
        singleSelect: true,
        showFooter:true,
        fit: true,
        fitColumns: true,
        queryParams: {
            ejzhId: $("#ejzhmx_detail_toolbar [name='ejzhId']").val(),
            nbgsId: $("#ejzhmx_detail_toolbar [name='nbgsId']").val(),
            dateStart: $("#ejzhmx_detail_toolbar [name='dateStart']").val(),
            endDate: $("#ejzhmx_detail_toolbar [name='dateEnd']").val()
        },
        columns: [
            [
                {field: 'gs', title: '运营商', width: 100, align: 'center',formatter: function(value,row,index){
                    if(!row["zhye"]) return "合计";
                    else return value;
                }},
                {field: 'kh', title: '代理客户', width: 100, align: 'center',formatter: function(value,row,index){
                    if(!row["zhye"]) return "";
                    else return value;
                }},
                {field: 'ejzh', title: '二级账户', width: 100, align: 'center',formatter: function(value,row,index){
                    if(!row["zhye"]) return "";
                    else return value;
                }},
                {field: 'jfje', title: '借方金额', width: 100, align: 'right',formatter:function(v){
                    return formatJe2(v, ",", ".");
                }},
                {field: 'dfje', title: '贷方金额', width: 100, align: 'right',formatter:function(v){
                    return formatJe2(v, ",", ".");
                }},
                {field: 'zhye', title: '账户余额', width: 100, align: 'right',formatter:function(v){
                    return formatJe2(v, ",", ".");
                }},
                {field: "bm", title: "收款编号", width: 70, align: 'center', formatter: function (value, row, index) {
                    if (value) {
                    return '<a href="#" id="ejzhmx_bm_sfkbm" class="ye1-linkbutton" style="color:red" sfkBm="' + row["bm"] + '" >' + value + '</a>';
                    }
                }},
                {field: 'xsdh', title: '销售单号', width: 100, align: 'center'},
                {field: 'mf2', title: '买方', width: 100, align: 'center'},
                {field: 'xsgs', title: '卖方', width: 100, align: 'center'},
                {field: 'lx', title: '票据类型', width: 100, align: 'center'},
                {field: 'shrq', title: '审核日期', width: 100, align: 'center'},
                {field: 'bz', title: '备注', width: 100, align: 'center'}
            ]
        ],
        onLoadSuccess: function () {
            $(".ye1-linkbutton").linkbutton({plain: true}).unbind("click").bind("click", function () {
                $.window({
                    title: '二级账户付款明细',
                    width: 1080,
                    height: 600,
                    cache: false,
                    maximizable: true,
                    url: $.webPath() + '/report/wlz/ejzhmx_fkmx_detail?sfkBm=' + $(this).attr("sfkBm"),
                    modal: true,
                    buttons: [],
                    onMaximize: function () {
                        $(this).find("#ejzhmx_grid").edatagrid("resize");
                    },
                    onRestore: function () {
                        $(this).find("#ejzhmx_grid").edatagrid("resize");
                    }
                });
            });
        }
    });
});
